<?php

// Load the Zend framework
require_once 'Zend/Loader.php';

// Load the Delicious object
Zend_Loader::loadClass('Zend_Service_Delicious');

// Grab the username and password
$username = strip_tags($_GET["delicious_username"]);
$password = strip_tags($_GET["delicious_password"]);

// Sanitize the URL, page title, tags and notes
$url   = urldecode($_GET["delicious_url"]);
$title = strip_tags(stripslashes($_GET["delicious_title"]));
$tags  = strip_tags($_GET["delicious_tags"]);
$notes = strip_tags(stripslashes($_GET["delicious_notes"]));

// Make sure notes is at least an empty string
if (!strlen($notes)) {
  $notes = "";
}

// Tags is either an empty string or an array
if (!strlen($tags)) {
  $notes = "";
} else {
  // Convert to array
  $tags = explode(" ", $tags);
}

// Make sure the title is at least an empty string
if (!strlen($title)) {
  $notes = "";
}

// Authenticate with Delicious
$delicious = new Zend_Service_Delicious($username, $password);

// create a new post and save it  (without method call chaining)
$newPost = $delicious->createNewPost($title, $url);
$newPost->setNotes($notes);
$newPost->setTags($tags);
$newPost->save();
?>
<br /><br />
<div style="padding-bottom:15px;padding-left:10px;color:#000;"><small>Your <a style="color:#000;" href="<?php echo $url; ?>">link</a> was posted to <a style="color:#000;" href="http://delicious.com/<?php echo $username ?>">your Delicious account</a>.</small></div>
